var ImageTransformUtils = {
	BoxIntegral: function(img, row, col, rows, cols) {
		var height = img.getHeight();
		var width = img.getWidth();

		// The subtraction by one for row/col is because row/col is inclusive.
		var r1 = Math.min(row, height) - 1;
		var c1 = Math.min(col, width) - 1;
		var r2 = Math.min(row + rows, height) - 1;
		var c2 = Math.min(col + cols, width) - 1;

		var A = (r1 >= 0 && c1 >= 0) ? img.getValue(c1, r1) : 0;
		var B = (r1 >= 0 && c2 >= 0) ? img.getValue(c2, r1) : 0;
		var C = (r2 >= 0 && c1 >= 0) ? img.getValue(c1, r2) : 0;
		var D = (r2 >= 0 && c2 >= 0) ? img.getValue(c2, r2) : 0;

		return Math.max(0, A - B - C + D);
	}
}

module.exports = ImageTransformUtils
